/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : bsp_flash_config.h
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.06.08
  - Brief         : board flash config
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
 * Update note:
 * ------------   ---------------   ----------------------------------
 *     Date            Author                      Note
 * ------------   ---------------   ----------------------------------
 *  2024.06.08       liuzhihua                 Create file
 ***/

#ifndef __BSP_FLASH_CONFIG_H__
#define __BSP_FLASH_CONFIG_H__
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "stm32_flash.h"
#ifdef __cplusplus
extern "C"
{
#endif
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/
/* Flash的最大页数见STM32参考手册 Flash module organization */
#define BSP_FLASH_MAX_PAGE      64  // Flash最大页数
#define BSP_FLASH_CFGSAVE_PAGE  63  // 保存配置参数使用的页数索引[0,max-1]

#if (BSP_FLASH_CFGSAVE_PAGE > BSP_FLASH_MAX_PAGE - 1)
#error "BSP_FLASH_CFGSAVE_PAGE must be less than BSP_FLASH_MAX_PAGE - 1"
#endif

//    配置参数控制结构体
typedef struct __BSP_ConfigInfoTypeDef
{
    uint32_t crc32;           //  CRC校验值
    uint32_t powerOnCount;    //  开机次数
  /* 用户添加存储到Flash的参数 */
    float openLockAngle;
    uint32_t autoCloseTime;
    char wifi_ssid[33];
    char wifi_pwd[33];
    char wifi_bssid[18];
    char mqtt_client_id[20];
    char mqtt_username[20];
    char mqtt_password[20];
    uint8_t mqtt_id_openLockAngle;
    uint8_t mqtt_id_autoCloseTime;
    uint8_t mqtt_id_lockCtrl;
} BSP_ConfigInfoTypeDef;



/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/
//      系统配置信息
extern BSP_ConfigInfoTypeDef sysCfgInfo;

__weak void bsp_flash_config_first_init(void);
void bsp_flash_config_init(void);
void bsp_flash_config_save(const void *arg);
void bsp_flash_config_save_start(void);

#ifdef __cplusplus
}
#endif
#endif
